
package com.weiqiao.mall.repository.impl;

import com.mongodb.client.MongoCollection;
import com.weiqiao.base.dao.impl.BaseMongoDaoImpl;
import com.weiqiao.mall.repository.IMarketActiveRepository;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author chenyudong
 * @date 2019/5/8
 * @desc
 */
@Repository("MarketActiveRepositoryImpl")
public class MarketActiveRepositoryImpl extends BaseMongoDaoImpl implements IMarketActiveRepository {

    private String collectionName = "wx_market_active_";

    private String collectionNameLog = "wx_market_activelog_";

    @Override
    public List<String> findMarketActiveList(Bson filter, int companyId) {
        return this.findFilter(collectionName + companyId, filter);
    }

    @Override
    public List<String> findMarketActiveList(Bson filter, Bson sort, int limit, int companyId) {
        return this.findFilterSortLimit(collectionName + companyId, filter, sort, limit);
    }

    @Override
    public boolean addMarketActive(String json, int company_id) {
        return this.inSert(collectionName + company_id, json);
    }

    @Override
    public boolean addMarketActiveLog(String json, int company_id) {
        return this.inSert(collectionNameLog + company_id, json);
    }

    @Override
    public String findOneMarketActive(Bson bson, int companyId) {
        return this.findOne(collectionName + companyId, bson);
    }

    @Override
    public int countByBson(Bson bson, int company_id) {
        MongoCollection<Document> dbCollection = getCollection(collectionName + company_id);
        return (int) dbCollection.count(bson);
    }

    @Override
    public List<String> getFlashsaleListByFilterSortSkipLimt(int company_id, Bson bson, Bson sort, int skip, int pageSize) {

        return this.findFilterSortSkipLimit(collectionName + company_id, bson, sort, skip, pageSize);
    }

    @Override
    public List<String> getAssemblyListByFilterSortSkipLimt(int company_id, Bson bson, Bson sort, int skip,
                                                            int pageSize) {
        return this.findFilterSortSkipLimit(collectionName + company_id, bson, sort, skip, pageSize);
    }

    @Override
    public List<String> findMarketActiveLogList(Bson filter, int companyId) {
        return this.findFilter(collectionNameLog + companyId, filter);
    }

    @Override
    public boolean updateOneMarketActive(Bson filter, Document doc, int company_id) {
        return this.updateOne(collectionName + company_id, filter, doc, false);
    }

    @Override
    public boolean updateOneMarketActiveLog(Bson filter, Document doc, int company_id) {
        return this.updateOne(collectionNameLog + company_id, filter, doc, false);
    }

}
